package com.ctyon.watchmanager.ui.activity;

import android.Manifest;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.ctyon.watchmanager.R;
import com.ctyon.watchmanager.ui.BaseActivity;
import com.ctyon.watchmanager.ui.fragment.LoginFragment;
import com.orhanobut.logger.Logger;
import com.tbruyelle.rxpermissions2.RxPermissions;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;

import static com.ctyon.common.container.ARouterPath.ROUTER_ACTIVITY_LOGIN;

/**
 * CreateDate：19-6-25 on 上午9:13
 * Describe:
 * Coder: lee
 */
@Route(path = ROUTER_ACTIVITY_LOGIN)
public class LoginActivity extends BaseActivity {

    private FragmentManager fragmentManager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_container);

        fragmentManager = getSupportFragmentManager();

        RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions.requestEach(Manifest.permission.INTERNET,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.UPDATE_DEVICE_STATS,
                Manifest.permission.RECORD_AUDIO,
                Manifest.permission.CAMERA,
                Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(granted -> {
                    Logger.i("rxPermissions : granted = " + granted);
                    if (granted.granted) { // Always true pre-M
                    } else {
                    }
                });

        loadFragment(savedInstanceState);
    }

    private void loadFragment(Bundle savedInstanceState) {
        Logger.i("loadFragment");
        if (savedInstanceState == null) {
            LoginFragment fragment = LoginFragment.newInstance();
            fragmentManager
                    .beginTransaction()
                    .add(R.id.fragment_container, fragment, LoginFragment.TAG)
                    .commit();
        }
    }

}
